/**
 * 路由区
 */
const indexRouter = require("./routers/index"); // 首页路由
const validateImage = require("./routers/validateImage"); // 图片验证码
const account = require("./routers/account"); // 用户相关路由
const template = require("art-template");
const csftProtect = require("./req_protect/csrf_protect"); // csrf防护

let routerApp = app => {
    app.use(csftProtect, indexRouter);
    app.use(csftProtect, validateImage);
    app.use(csftProtect, account);


    /**
     * 设置过滤器
     */
    // 头像
    template.defaults.imports.avatar_url = function(value){
        if(!value){
            return "/images/person01.png"
        } else {
            return value;
        }
    };

     // 创建时间
     template.defaults.imports.create_time = function(value){
       let dateTime = "";
       let year = value.getFullYear();
       let month = value.getMonth() + 1;
       let date = value.getDate();
       let hours = value.getHours();
       let minutes = value.getMinutes();
       let seconds = value.getSeconds();
       return `${year}-${month}-${date} ${hours}:${minutes}:${seconds}`;
    };

    // 排行榜前三样式
    template.defaults.imports.rank_class = function(value){
        let style = "";
        let rank = value + 1;
        switch(rank){
            case 1:
                style = "first";
                break;
            case 2:
                style = "second";
                break;
            case 3:
                style = "third";
        }
        
        return style;
    }

}

module.exports = routerApp;

